﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DLM.Infrastructure.Domain;

namespace DLM.Domain.Model
{
    public class Photo : IValidatableObject, IAggregateRoot
    {
        public int PhotoID { get; set; }

        [Required(ErrorMessage="请选择正确的用户")]
        public int UserID { get; set; }

        [Required(ErrorMessage="照片不允许为空")]
        [StringLength(30, ErrorMessage = "最大长度为30")]
        public string Url { get; set; }

         [StringLength(20, ErrorMessage = "最大长度为20")]
        public string Desc { get; set; }

        public bool IsMain { get; set; }
        public DateTime CreateDate { get; set; }
        public virtual User User { get; set; }

        public IEnumerable<ValidationResult> Validate(ValidationContext validationContext)
        {
            if (string.IsNullOrEmpty(Url))
            {
                yield return new ValidationResult("图片不允许为空", new string[] { "Url" });
            }
        }
    }
}
